<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
        .has-no{color:#3366cc;}
        .has-success{color: #1ab394;}
        .has-warning{color: #f8ac59;}
        .has-error{color: #ed5565;}
        .has-receive{color: #9E792E;}
        .remark {
            width: 100%; /*自动适应父布局宽度*/
            overflow: auto;
            word-break: break-all;
        }
    </style>
    <%}%>
</head>

<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                    <div class="form-group">
                        <label class="control-label col-sm-1">状态:</label>
                        <div class="col-sm-2">
                            <select name="flag"  class="form-control">
                                <option value="">全部分类</option>
                                <option value="0">未付款</option>
                                <option value="1">已付款</option>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">供应商:</label>
                        <div class="col-sm-2">
                            <input type="text" id="produceSupplierName" name="produceSupplierName" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">PO号:</label>
                        <div class="col-sm-2">
                            <input type="text" id="produceNo" name="produceNo" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">柜号:</label>
                        <div class="col-sm-2">
                            <input type="text" id="createPlanNo" name="createPlanNo" class="form-control">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-sm-1">时间类型:</label>
                        <div class="col-sm-2">
                            <select id="type" name="type"  class="form-control">
                                <option value="">请选择</option>
                                <option value="1">出货时间</option>
                                <option value="2">付款时间</option>
                                <option value="3">创建时间</option>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">开始时间:</label>
                        <div class="col-sm-2">
                            <input type="text" name="beginDate" id="beginDate" placeholder="请选择开始时间" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">结束时间:</label>
                        <div class="col-sm-2">
                            <input type="text" name="endDate" id="endDate" placeholder="请选择结束时间" class="form-control">
                        </div>

                    </div>

                    <div class="form-group">
                        <label class="control-label col-sm-1">付款信息:</label>
                        <div class="col-sm-2">
                            <select  name="produceRemark" class="form-control">
                                <option value="">全部分类</option>
                                <option value="预付款">预付款</option>
                                <option value="付款">付款</option>
                            </select>
                        </div>

                        <label class="control-label col-sm-1">付款方式:</label>
                        <div class="col-sm-2">
                            <select  name="paymentType" id="paymentType" class="form-control">
                                <option value="">请选择付款方式</option>
                                <%for(var dict in payment){%>
                                <option value="${dict.detailName}"  >${dict.detailName}</option>
                                <%}%>
                            </select>
                        </div>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                <button  class="export-btn layui-btn  layui-btn-sm" style="margin-left: -2px">
                    <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
                </button>
                <button  class="report-btn layui-btn  layui-btn-sm btn-info"  style="">
                    <i class="fa fa-check-square-o" aria-hidden="true"></i> 批量付款
                </button>

            </div>
    <!-- START 数据表格 -->
    <table id="portTable"
           data-toolbar="#toolbar"
           data-side-pagination="server"
           data-pagination="true"
           data-resizable="true"
           data-url="/sea/finance/produce/payment/findByCnd.do"
           data-page-size="15"
           class="table table-striped table-hover"
    >
    </table>
        </div>
    </div>
    <!-- END 数据表格 -->
</div>



<div id="layer_pay_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
            <input type="hidden" id="id" name="id">
            <div class="form-group" style="margin-top: 20px">
                <label class=" control-label col-sm-2" style="max-width: 100px">是否付款</label>
                <div class="col-sm-6" style="max-width: 400px;">
                    <select  id="flag" name="flag" class="form-control">
                        <option value="0" selected>否</option>
                        <option value="1" >是</option>
                    </select>
                </div>
            </div>

            <div class="form-group check" style="margin-top: 20px">
                <label class=" control-label col-sm-2" style="max-width: 100px">上传凭证</label>
                <div class="col-sm-6" style="max-width: 400px;">
                    <a class="club-import-btn ">
                        <button  class="layui-btn layui-btn-sm " style="margin-left: -2px" type="button" id="import-btn-file2"  name="import-btn-file2">
                            <i class="layui-icon"></i>导入凭证附件1
                        </button>
                    </a>
                    <input type="hidden" name="produceFile" id="produceFile">
                </div>
            </div>

            <div class="form-group check" style="margin-top: 20px">
                <label class=" control-label col-sm-2" style="max-width: 100px">付款金额</label>
                <div class="col-sm-6" style="max-width: 400px;">
                   <input type="text" name="producePay" class="form-control" id="producePay">
                </div>
            </div>
            <div class="form-group check" style="margin-top: 20px">
                <label class=" control-label col-sm-2" style="max-width: 100px">付款时间</label>
                <div class="col-sm-6" style="max-width: 400px;">
                    <input type="text" name="producePayTime" class="form-control" id="producePayTime">
                </div>
            </div>

            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-pay-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>



<div id="layer_all_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-all-form" method="post" autocomplete="off" style="margin: auto">

            <div class="form-group" style="margin-top: 20px">
                <label class=" control-label col-sm-2" style="max-width: 100px">付款时间</label>
                <div class="col-sm-6" style="max-width: 400px;">
                    <input type="text" name="producePayTime" id="produceAllPayDate" class="form-control" >
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class=" control-label col-sm-2" style="max-width: 100px">上传凭证</label>
                <div class="col-sm-6" style="max-width: 400px;">
                    <a class="club-import-btn ">
                        <button  class="layui-btn layui-btn-sm " style="margin-left: -2px" type="button" id="import-btn-file"  name="import-btn-file">
                            <i class="layui-icon"></i>导入凭证附件1
                        </button>
                    </a>
                    <input type="hidden" name="produceFile2" id="produceFile2">
                </div>
            </div>

            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-all-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,chosen,chosen-demo,layui,upload'}){}%>
<script>
    var ind=null;
    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-btn-file', //绑定元素,
            accept:'file',
            url: '/sea/physical/refusedTax/import/', //上传接口
            data:{},
            before:function () {
                ind= layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $("#produceFile2").val(data.data);
                        // parent.$relatedTable.bootstrapTable('refresh');
                        layer.close(ind);
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.closeAll();
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-btn-file2', //绑定元素,
            accept:'file',
            url: '/sea/physical/refusedTax/import/', //上传接口
            data:{},
            before:function () {
                ind= layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $("#produceFile").val(data.data);
                        // parent.$relatedTable.bootstrapTable('refresh');
                        layer.close(ind);
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.closeAll();
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });
    laydate.render({
        elem: '#beginDate',
        type: 'date',
        format: 'yyyy-MM-dd',
        trigger: 'click'
    });
    laydate.render({
        elem: '#endDate',
        type: 'date',
        format: 'yyyy-MM-dd',
        trigger: 'click'
    });
    laydate.render({
        elem: '#producePayTime' //指定元素
        ,trigger: 'click'
    });
    laydate.render({
        elem: '#produceAllPayDate' //指定元素
        ,trigger: 'click'
    });
    var $portTable = $('#portTable');
    $(function(){
        $(".check").hide();
        $("#flag").change(function () {
            var flag=$("#flag").val();
            if(flag==0){
                $(".check").hide();
            }else{
                $(".check").show();
            }
        });

        //START 表格配置
        $portTable.bootstrapTable({
            columns: [
                {
                    field: 'state',
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '采购单号',
                    field: 'produceNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '合同号',
                    field: 'produceAgreement',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '渠道',
                    field: 'orderChannelName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '供应商',
                    field: 'produceSupplierName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '币种',
                    field: 'produceMoneyType',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '出货金额',
                    field: 'producePayment',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '付款信息',
                    field: 'produceRemark',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '付款方式',
                    field: 'paymentType',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '账期',
                    field: 'supplierDay',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '核销状态',
                    field: 'produceIsCheck',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '核销金额',
                    field: 'produceCheckMoney',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '杂项费',
                    field: 'produceUnusualMoney',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r){
                        if(null==v){
                            return 0;
                        }else {
                            return v;
                        }
                    }
                },{
                    title: '实际需付款',
                    field: '',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        return (r.producePayment-r.produceCheckMoney-r.produceUnusualMoney).toFixed(2);
                    }
                },
                {
                    title: '付款状态',
                    field: 'flag',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(v==1){
                            return '已付款';
                        }else{
                            return '未付款';
                        }
                    }
                },
                {
                    title: '付款金额',
                    field: 'producePay',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '付款凭证',
                    field: 'produceFile',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(r.flag==1 && null != r.produceFile && r.produceFile!=''){
                            var result='<button  class="download-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">';
                            result+='<i class="fa fa-download" aria-hidden="true"></i> <a href="'+v+'" download style="color: white">下载附件</a>';
                            result+='</button>';
                            return result;
                        }
                    }
                },
                {
                    title: '出货时间',
                    field: 'produceOutTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '付款时间',
                    field: 'producePayTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜号',
                    field: 'createPlanNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '备注',
                    field: 'produceReason',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '付款备注(表头)',
                    field: 'producePaymentRemark',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '付款状态(表头)',
                    field: 'producePaymentStatus',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(v==1){
                            return '无异常';
                        }else{
                            return '';
                        }
                    }
                },
                {
                    title: '创建时间',
                    field: 'createTime',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v, r) {
                        return v.substr(0,10);
                    }
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                //新增
                $('.pay-btn').on('click',function(){//新增
                    var id = $(this).attr('data-val');
                    $("#id").val(id);
                    var pay=$(this).attr("data-val-no");
                    var check=$(this).attr("data-val-check");
                    var unusual=$(this).attr("data-val-unusual");

                    if(null==unusual || 'null'==unusual){
                        unusual=0;
                    }
                    $("#producePay").val((pay-check-unusual).toFixed(2));
                    layer.open({
                        type:1,
                        title:'预付款',
                        area:['600px','450px'],
                        skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                        shadeClose:false,
                        resize: false,
                        scrollbar: false,
                        maxmin: false,//出现最大化按钮
                        content:$('#layer_pay_window')
                    })
                });
            }
        });
        //操作菜单
        function optFormatter(value,row){
            var content = '';
            if(row.flag==0) {
                content += '<button class="pay-btn btn btn-xs btn-success" data-val-unusual="' + row.produceUnusualMoney + '" data-val-check="' + row.produceCheckMoney + '" data-val-no="' + row.producePayment + '" data-val="' + row.id + '" title="付款"><i class="fa fa-check-square-o" aria-hidden="true"></i> 付款 </button>';
            }
            return content;
        }
        //END 表格配置
    });


    $('.search-btn').on('click',function(){
        $portTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/finance/produce/payment/findByCnd.do?'+$('#search-form').serialize() });
    });

    //提交表单
    $('.save-pay-btn').on('click',function(){
        var producePayTime=$("#producePayTime").val();
        if(producePayTime==''){
            layer.msg("付款时间不能为空！",{icon: 0,time:1500,shade: [0.8, '#393D49']});
            return false;
        }
        layer.confirm('确定要付款当前数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){

            layer.closeAll();
            var index=layer.load();
            $.post('/sea/supply/produce/payment/usave.do',{id:$("#id").val(),
                                                          produceFile:$("#produceFile").val(),
                                                          producePay:$("#producePay").val(),
                                                          producePayTime:$("#producePayTime").val(),
                                                          flag:$("#flag").val()},function(data){
                if( data.ok ){
                    $portTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            });
        });
    });



    $("#importSession").on("change",function(){
        var formFile = new FormData($('#info-form')[0]);
        var index=layer.load(1, {
            shade: [0.1,'#fff'],
            zIndex : 1111//0.1透明度的白色背景
        });
        $.ajax({
            url: "/upload/uploadFile",
            data: formFile,
            type: "post",
            success: function (data) {
                console.log(data);
                if(data.ok){
                    parent.layer.msg("上传成功！",{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    $("#produceFile").val(data.data);
                    layer.close(index);
                }else{
                    parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            },
        });
    });

    $("#importSession2").on("change",function(){
        var formFile = new FormData($('#info-form')[0]);
        var index=layer.load(1, {
            shade: [0.1,'#fff'],
            zIndex : 1111//0.1透明度的白色背景
        });
        var index= layer.load(2, { //icon支持传入0-2
            shade: [0.1, '#fff'], //0.5透明度的灰色背景
            content: '正在上传凭证,请稍后...',
            success: function (layero) {
                layero.find('.layui-layer-content').css({
                    'padding-top': '39px',
                    'margin-left': '-50px',
                    'width': '300px',
                    'font-color': 'red',
                    'font-size': '20px'
                });
            }
        });
        $.ajax({
            url: "/upload/uploadFile",
            data: formFile,
            type: "post",
            processData: false,//用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须
            success: function (data) {
                console.log(data);
                if(data.ok){
                    parent.layer.msg("上传成功！",{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    $("#produceFile2").val(data.data);
                    layer.close(index);
                }else{
                    parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            },
        });
    });

    $(".export-btn").click(function () {
        window.location.href='/sea/finance/produce/payment/export?'+$('#search-form').serialize();
    });

    $('.report-btn').on('click',function () {
        var selDatas = $portTable.bootstrapTable('getSelections');
        if( selDatas.length == 0 ){
            layer.msg('请选择要生成的数据',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else {
            layer.open({
                type: 1,
                title: '批量付款',
                area: ['600px', '450px'],
                skin: 'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                shadeClose: false,
                resize: false,
                scrollbar: false,
                maxmin: false,//出现最大化按钮
                content: $('#layer_all_window')
            })
        }
    });

    $(".save-all-btn").on('click',function () {

        var selDatas = $portTable.bootstrapTable('getSelections');
        if( selDatas.length == 0 ){
            layer.msg('请选择要生成的数据',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else{
            var produceAllPayDate=$("#produceAllPayDate").val();
            var produceFile2=$("#produceFile2").val();
            var ids = [];
            var flag=true;
            $.each(selDatas,function(i,d){
                ids.push(d.id);
            });
            ids = ids.join(',');
            if(flag==true) {
                var inde= layer.load(2, { //icon支持传入0-2
                    shade: [0.1, '#fff'], //0.5透明度的灰色背景
                    content: '正在批量付款,请稍后...',
                    success: function (layero) {
                        layero.find('.layui-layer-content').css({
                            'padding-top': '39px',
                            'margin-left': '-50px',
                            'width': '300px',
                            'font-color': 'red',
                            'font-size': '20px'
                        });
                    }
                });
                $.ajax({
                    url: "/sea/finance/produce/payment/pay",
                    data: {
                        producePayTime:produceAllPayDate,
                        produceFile:produceFile2,
                        payIds:ids
                    },
                    type: "post",
                    success: function (data) {
                        if(data.ok){
                            layer.msg("生成成功！",{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                                    layer.closeAll();
                                    $portTable.bootstrapTable('refresh');
                                }});
                        }else{
                            layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                                    layer.closeAll();
                                }});
                        }
                    },
                });
            }
        }
    })
</script>
</body>
</html>
